package com.dream.service2.controller;

import com.dream.service2.utils.RedisUtil;
import com.dream.service2.utils.ReturnUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value="/redis")
public class RedisController  {
    @Autowired
    RedisUtil redisUtil;


    /**
     * @auther: zhangyingqi
     * @date: 16:23 2018/8/29
     * @param: []
     * @return: org.springframework.ui.ModelMap
     * @Description: 执行redis写/读/生命周期
     */
    @RequestMapping(value = "getRedis",method = RequestMethod.POST)
    @ResponseBody
    public ReturnUtils getRedis(){
        redisUtil.set("20182018","这是一条测试数据", 0);
        Long resExpire = redisUtil.expire("20182018", 60, 0);//设置key过期时间
        String res = redisUtil.get("20182018", 0);
        return ReturnUtils.success("操作成功",res);
    }
}

